# Title: ACEPTAR EL TRACLADO                          		     Filename: NumPrim.s
# Autho: MUNIVE SALDAÑA EVANS JOSUE					                   Date: 9 / Mar / 2017
# Description: Teclado
# Input: -
# Output:

@ Teclado.s

.section        .bss
.comm buffer, 48

.section        .data
msg:
        .ascii "Introduce un numero"
        msgLen = . - msg
        
.section        .text
.globl  _start
_start:

mov r00, $1
ldr r1, =msg
ldr r2, =msgLen
mov r7, $4
svc $0

mov r7, $3
mov r0, $1
ldr r1, =buffer
mov r2, $0x30
svc $0

ldrb r2, [r1]
mov r3, $0

pushDigits:
stmfd   sp!, {r2}
add     r3, r3, $1
ldrb    r2,[r1, #1]!
cmp     r2, $0xA
beq     convDigits
bne     pushDigits

convDigits:
mov r4, $1
mov r0, $0
mov r6, $0

jumpBack:
ldmfd   sp!, {r2}
cmp     r2, $0x30
blt     error
cmp     r2, $x39
bgt     error
sub     r2, r2, $0x30
mul     r2, r4, r2
add     r0, r0, r2
add     r6, r6, r1
cmp     r6, r3
beq     exit
mov     r5, r4, lsl, $3
add     r4, r5, r4, lsl $1
bal jumpBack

error:
mov r0, $-1
bal exit

exit:
mov r7, $1
svc $0
.end
